Skip to content

fix(detectors/aws/lambda): return nil error when not running on Lambda - #9464

Open
pujitha24 wants to merge 2 commits into
open-telemetry:mainfrom
pujitha24:auto/issue-8629
Open

fix(detectors/aws/lambda): return nil error when not running on Lambda#9464
pujitha24 wants to merge 2 commits into
open-telemetry:mainfrom
pujitha24:auto/issue-8629

Conversation

@pujitha24

Copy link
Copy Markdown
Contributor

Motivation:
The Lambda resource detector returned a non-nil error whenever the
AWS_LAMBDA_FUNCTION_NAME environment variable was unset, i.e. whenever
the process was not running inside AWS Lambda. This makes the detector
unusable in generic, multi-environment detector chains: any caller
that treats a detector error as fatal (for example
xrayconfig.NewTracerProvider, which returns the error from
detector.Detect verbatim) fails outright outside of Lambda instead of
simply contributing no attributes. This is inconsistent with sibling
detectors in this repository, such as the EKS and ECS detectors, which
return a nil error and an empty resource once they determine they are
not running in their respective target environment.

Approach:
Change resourceDetector.Detect to return (empty, nil) instead of
(empty, errNotOnLambda) when AWS_LAMBDA_FUNCTION_NAME is unset, and
remove the now-unused errNotOnLambda sentinel error. The resource
returned is unchanged (still empty); only the error contribution
changes from non-nil to nil, matching the no-op behavior used by
go.opentelemetry.io/contrib/detectors/aws/ecs and
go.opentelemetry.io/contrib/detectors/aws/eks.

Validation:

  • go test ./... in detectors/aws/lambda: all tests pass. The updated
    TestReturnsIfNoEnvVars asserts assert.NoError(t, err) instead of
    assert.Equal(t, errNotOnLambda, err); confirmed this test fails
    against the previous code (returns errNotOnLambda) and passes with
    this change, i.e. it is a genuine failing-then-passing regression
    test for this defect.
  • go build ./... and go vet ./... in detectors/aws/lambda: pass.
  • golangci-lint run ./... in detectors/aws/lambda: 0 issues.
  • go mod tidy at the repository root: no diff to go.mod/go.sum.
  • Searched all in-repo usages of this detector (autodetect.go,
    xrayconfig.go, the package example) for reliance on the old error
    value or type; none check errNotOnLambda specifically, so this is
    not a breaking change for any in-repo caller.

Report: #8629
Signed-off-by: Pujitha Paladugu 10557236+pujitha24@users.noreply.github.com

Fixes #8629

Motivation:
The Lambda resource detector returned a non-nil error whenever the
AWS_LAMBDA_FUNCTION_NAME environment variable was unset, i.e. whenever
the process was not running inside AWS Lambda. This makes the detector
unusable in generic, multi-environment detector chains: any caller
that treats a detector error as fatal (for example
xrayconfig.NewTracerProvider, which returns the error from
detector.Detect verbatim) fails outright outside of Lambda instead of
simply contributing no attributes. This is inconsistent with sibling
detectors in this repository, such as the EKS and ECS detectors, which
return a nil error and an empty resource once they determine they are
not running in their respective target environment.

Approach:
Change resourceDetector.Detect to return (empty, nil) instead of
(empty, errNotOnLambda) when AWS_LAMBDA_FUNCTION_NAME is unset, and
remove the now-unused errNotOnLambda sentinel error. The resource
returned is unchanged (still empty); only the error contribution
changes from non-nil to nil, matching the no-op behavior used by
go.opentelemetry.io/contrib/detectors/aws/ecs and
go.opentelemetry.io/contrib/detectors/aws/eks.

Validation:
- go test ./... in detectors/aws/lambda: all tests pass. The updated
  TestReturnsIfNoEnvVars asserts assert.NoError(t, err) instead of
  assert.Equal(t, errNotOnLambda, err); confirmed this test fails
  against the previous code (returns errNotOnLambda) and passes with
  this change, i.e. it is a genuine failing-then-passing regression
  test for this defect.
- go build ./... and go vet ./... in detectors/aws/lambda: pass.
- golangci-lint run ./... in detectors/aws/lambda: 0 issues.
- go mod tidy at the repository root: no diff to go.mod/go.sum.
- Searched all in-repo usages of this detector (autodetect.go,
  xrayconfig.go, the package example) for reliance on the old error
  value or type; none check errNotOnLambda specifically, so this is
  not a breaking change for any in-repo caller.

Report: open-telemetry#8629
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
@pujitha24
pujitha24 requested a review from a team as a code owner August 13, 2026 05:04
@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.5%. Comparing base (2175b1c) to head (9f066c2).

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #9464   +/-   ##
=====================================
  Coverage   84.5%   84.5%           
=====================================
  Files        203     203           
  Lines      16805   16805           
=====================================
+ Hits       14204   14215   +11     
+ Misses      2121    2110   -11     
  Partials     480     480           
Files with missing lines Coverage Δ
detectors/aws/lambda/detector.go 90.0% <100.0%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ps-mir ps-mir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changelog entry needs a correction. No other concerns.

Comment thread CHANGELOG.md Outdated

### Fixed

- `go.opentelemetry.io/contrib/detectors/aws/lambda` no longer returns an error when run outside of an AWS Lambda environment, matching the no-op behavior of other resource detectors.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think new entries in changelog are appended. This should move to bottom of the list.

Per review feedback from ps-mir, new entries should be appended rather
than prepended.

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
@pujitha24

Copy link
Copy Markdown
Contributor Author

Moved the entry to the bottom of the Fixed list, thanks for catching that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Lambda detector returns error if not run in Lambda

3 participants